package com.clementheliou.cheliou.dal.model.photo;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;

import com.clementheliou.cheliou.dal.model.base.BaseEntity;
import com.clementheliou.cheliou.dal.model.member.enumeration.MemberLocale;

/**
 * Entity dedicated to the author's notes about photos.
 * 
 * @author Clément HELIOU (clement.heliou@gmail.com)
 * @see {@link BaseEntity};
 * @see {@link Entity};
 * @see {@link Serializable};
 * @see {@link Table};
 * @see {@link UniqueConstraint}.
 * @since 1.0
 */
@Entity
@Table(name = "authorsnote", uniqueConstraints = { @UniqueConstraint(columnNames = "photoid"), @UniqueConstraint(columnNames = "locale") })
public class AuthorsNote extends BaseEntity implements Serializable {

	/**
	 * UID for serialization.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private static final long serialVersionUID = -5889199204519711451L;

	/**
	 * The photo the note is related to.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @see {@link Photo}.
	 * @since 1.0
	 */

	private Photo annotatedPhoto;

	/**
	 * The note's locale.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private MemberLocale locale;

	/**
	 * The note's content.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String content;

	/*
	 * Getters & setters.
	 */

	@GeneratedValue(generator = "seq_authorsnote")
	@Id
	@SequenceGenerator(name = "seq_authorsnote", sequenceName = "seq_authorsnote")
	public Integer getId() {
		return id;
	}

	@ManyToOne
	@JoinColumn(name = "photoid", nullable = false)
	public Photo getAnnotatedPhoto() {
		return annotatedPhoto;
	}

	public void setAnnotatedPhoto(Photo annotatedPhoto) {
		this.annotatedPhoto = annotatedPhoto;
	}

	@Basic(optional = false)
	@Column(length = 100, nullable = false)
	@Enumerated(EnumType.STRING)
	@NotNull
	public MemberLocale getLocale() {
		return locale;
	}

	public void setLocale(MemberLocale locale) {
		this.locale = locale;
	}

	@Basic(optional = false)
	@Column(name = "note", nullable = false)
	@NotNull
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
}
